package ar.fiuba.tp7552.buildadmin.tags;

import java.io.IOException;
import java.io.Writer;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.components.Component;

import com.opensymphony.xwork2.util.ValueStack;

public class ConfirmDialog extends Component {

	private String title;
	private String confirmAction;
	private String cancelAction;
	private String urlBase;
	
	public ConfirmDialog(ValueStack stack) {
		super(stack);
	}
	
	public boolean start(Writer writer) {
		try {
			writer.write("\n");
			writer.write("<div style=\"height: 60px\"></div>\n");
			writer.write("<div id=\"rightnow\" style=\"width: 80%;margin-left: 80px\">\n");
			writer.write("<h3 class=\"reallynow\">\n");
			writer.write("<span>"+title+"</span>\n");
			writer.write("<br />\n");
			writer.write("</h3>\n");
			writer.write("<div align=\"center\">\n");
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}	
		return true;
    }
	
	

	@Override
	public boolean end(Writer writer, String body) {
		try {
			writer.write("<br/>\n");
			writer.write("<a href=\""+urlBase+"/"+confirmAction+"\" class=\"button medium\">Aceptar</a>\n");
			if (StringUtils.isNotEmpty(cancelAction)) {
				writer.write("<a href=\""+urlBase+"/"+cancelAction+"\" class=\"button medium\">Cancelar</a>\n");
			}
			writer.write("</div>\n");
			writer.write("<div style=\"height: 5px\"></div>\n");
			writer.write("</div>\n");
			writer.write("<div style=\"height: 60px\"></div>\n");
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
		return true;
	}
	
	public String getUrlBase() {
		return urlBase;
	}

	public void setUrlBase(String urlBase) {
		this.urlBase = urlBase;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getConfirmAction() {
		return confirmAction;
	}

	public void setConfirmAction(String confirmAction) {
		this.confirmAction = confirmAction;
	}

	public String getCancelAction() {
		return cancelAction;
	}

	public void setCancelAction(String cancelAction) {
		this.cancelAction = cancelAction;
	}
}
